<?php
/*
 +----------------------------------------------------------------------
 + Title        : SysSeting 控制器
 + Author       : Randy_chen
 + Version      : V1.0.0.1
 + Initial-Time : 2021/3/2 6:57
 + Last-time    : 2021/3/2 6:57+ chen2
 + Desc         : SysSeting
 +----------------------------------------------------------------------
*/


namespace app\admin\controller;


use app\admin\controller\AdminBaseController;
use app\common\attributes\Menu;
use app\common\model\Setting;
use app\common\service\SysSettingService;
use think\annotation\Inject;
use think\App;

use function get_setting;

class SettingController extends AdminBaseController {
    #[Inject]
	protected SysSettingService $service;

    #[Inject]
    protected Setting $model;

    /**
     * @param string $id
     * @return \think\Response|\think\response\Json|\think\response\Jsonp|\think\response\Redirect|\think\response\Xml
     * @throws \Exception
     */
    #[Menu('修改系统配置')]
	public function update($key){
		$data = $this->getParams();
        $add['value'] = $data['value'];
        $this->service->setSysSettingItem($add, $key);
		return $this->returnSuccess();
	}

    /**
     * @return \think\Response|\think\response\Json|\think\response\Jsonp|\think\response\Redirect|\think\response\Xml
     * @throws \think\db\exception\DataNotFoundException
     * @throws \think\db\exception\ModelNotFoundException
     * @throws \think\exception\DbException
     * @throws \Exception
     */
    #[Menu('查看系统配置列表')]
	public function index(){
        $data = $this->getParams();
        //当前是否为关联查询
        $this->relationSearch = true;
        //设置过滤方法
        $this->request->filter(['trim']);
        $extendQueryHelper = $this->buildParams();
        $list = $this->service->getSysSettingList($extendQueryHelper, $data);
        foreach ($list as $row) {
        }
        return $this->success($list);
	}
    #[Menu('查看系统配置')]
    public function read($key){
        $res = $this->service->getSysSettingItem($key);
        return $this->returnSuccess($res);
    }

    //获取配置字典
    public function tree(){
        $result = SysSettingService::tree();
        return $this->returnSuccess($result);
    }
}